package com.cen.dao.user;

import com.cen.dao.BaseDao;
import com.cen.domain.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author : cen
 * @date : 2020/5/18 8:12
 */
public class IUserDaoImpl implements IUserDao {
    @Override
    public User getLoginUser(Connection connection, String userCode) throws SQLException {
        PreparedStatement pstm = null;
        ResultSet resultSet = null;
        User user = null;
        if(connection != null){
        String sql = "select *from smbms_user where userCode = ?";
        Object []param = {userCode};

        resultSet = BaseDao.excute(connection, pstm, resultSet, sql, param);
        while (resultSet.next()){
            user = new User();
            user.setId(resultSet.getInt("id"));
            user.setUserCode(resultSet.getString("userCode"));
            user.setUserName(resultSet.getString("userName"));
            user.setUserPassword(resultSet.getString("userPassword"));
            user.setGender(resultSet.getInt("gender"));
            user.setBirthday(resultSet.getDate("birthday"));
            user.setPhone(resultSet.getString("phone"));
            user.setAddress(resultSet.getString("address"));
            user.setUserRole(resultSet.getInt("userRole"));
            user.setCreatedBy(resultSet.getInt("createdBy"));
            user.setModifyDate(resultSet.getDate("modifyDate"));

        }
        BaseDao.closeResource(connection,pstm,resultSet);
        }
        return user;

    }
}
